package com.xx566.blog.common;

import com.jfinal.plugin.ehcache.IDataLoader;
import com.xx566.blog.model.Article;
import com.xx566.blog.model.Friendly;
import com.xx566.blog.model.Message;
import com.xx566.blog.model.Tags;

public class XX566Cache {

	public static enum CacheKey {
		tags, friendlys, articles, messages, archives, cates
	}

	public static IDataLoader getIDataLoaderByKey(final CacheKey cacheKey) {
		final IDataLoader iDataLoader = new IDataLoader() {
			@Override
			public Object load() {
				switch (cacheKey) {
				case tags:
					return Tags.dao.findAll();
				case friendlys:
					return Friendly.dao.findAll();
				case archives:
					return Article.dao.findAllArchiveTimes();
				case articles:
					return Article.dao.findArticles4Page(1, 10, 0, "0-0", 0,
							false);
				case messages:
					return Message.dao.findMessages4Page(1, 10);
				case cates:
					return Tags.dao.findCateList();
				}
				return null;
			}
		};
		return iDataLoader;
	}

}
